<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/my.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
    <span class="layui-breadcrumb">
      <a href="">首页</a>
      <a href="">入库管理</a>
      <a>
        <cite>采购退货</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" id="searchForm" method="get" action="/return">
            <div class="layui-input-inline">
                <select id="condition" name="condition" lay-filter="switchItem" style="text-align-last: center;">
                    <option value="产品名">产品名</option>
                    <option value="供应商">供应商</option>
                    <option value="采购员">采购员</option>
                    <option value="退货日期范围查询">退货日期范围查询</option>
                </select>
            </div>
            <!--            记录上次查询是什么查询-->
            <input th:value="${preCondition}" type="text" id="preCondition" style="display: none"
                   name="preCondition" autocomplete="off" class="layui-input">
            <!--        单输入框查询-->
            <input type="text" id="conValue" name="conValue" placeholder="请输入查询内容" autocomplete="off" class="layui-input">
            <!--        日期区间查询-->
            <input th:value="${start}" class="layui-input" placeholder="开始日" name="startDate" id="startDate">
            <input th:value="${end}" class="layui-input" placeholder="截止日" name="endDate" id="endDate">
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>

    <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="x_admin_show('添加退货信息','/insertReturn',400,500)"><i
                class="layui-icon"></i>添加</button>
    </xblock>
    <table class="layui-table" id="returnTabel">
        <thead>
        <tr>
            <th>
                <input class="layui-unselect header layui-form-checkbox" lay-skin="primary" name="getId" th:value="${returnId}"><i class="layui-icon">&#xe605;</i>
                </input>
            </th>
            <th style="display: none">退货编号</th>
            <th>仓库名称</th>
            <th>退货产品</th>
            <th>退货数量</th>
            <th>退货总金额</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="i:${info.returnList}">
            <td>
                <input type="checkbox" name="getId" th:value="${i.returnId}">
            </td>
            <td th:text="${i.returnId}" style="display: none"></td>
            <td th:text="${i.storageName}"></td>
            <td th:text="${i.productName}"></td>
            <td th:text="${i.returnNum}"></td>
            <td th:text="${i.returnMoney}"></td>
            <td class="td-manage">

                <a title="查看详情" onclick="return_detail(this)" href="javascript:;">
                    <i class="layui-icon">&#xe60b;</i>
                </a>

                <a title="编辑" onclick="return_edit(this)" href="javascript:;">
                    <i class="layui-icon">&#xe642;</i>
                </a>

                <a title="删除" onclick="return_del(this)" href="javascript:;">
                    <i class="layui-icon">&#xe640;</i>
                </a>

            </td>
        </tr>
        </tbody>
    </table>

    <div class="x-so">
        <a class="layui-btn layui-btn-sm" th:href="@{/return(page=1)}">首页</a>
        <a class="layui-btn layui-btn-sm" th:href="@{/return(page=${info.pre})}" >上一页</a>
        <a class="layui-btn layui-btn-primary ayui-btn-sm" th:text="${info.cur}"></a>
        <a class="layui-btn layui-btn-sm" th:href="@{/return(page=${info.next})}" >下一页</a>
        <a class="layui-btn layui-btn-sm" th:href="@{/return(page=${info.totalPage})}">末页</a>
        共<span th:text="${info.total}"></span>条数据
        共<span th:text="${info.totalPage}"></span>页
    </div>

</div>
<script>

    function singleInput() {
        var preCondition = $("#preCondition").val();
        if(preCondition == "退货日期范围查询"){
            $("#condition").val("退货日期范围查询");
            $("#startDate").show();
            $("#endDate").show();
            $("#conValue").hide();
        }else{
            $("#startDate").hide();
            $("#endDate").hide();
            $("#conValue").show();
        }
    }

    //定义文档加载函数
    $(function(){
        //查询使得输入框为单输入框
        singleInput();
    })

    layui.use(['layer', 'jquery', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        //根据不同条件显示不同的input框
        form.on('select(switchItem)', function(data){
            if(data.value == "退货日期范围查询"){
                $("#startDate").show();
                $("#endDate").show();
                $("#conValue").hide();
            }else{
                $("#startDate").hide();
                $("#endDate").hide();
                $("#conValue").show();
            }
        });

        //根据条件进行搜索
        form.on('submit(search)', function(data){
            document.getElementById("searchForm").submit();
        });
    });

    layui.use('laydate', function () {
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
    elem: '#startDate' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
    elem: '#endDate' //指定元素
    });
    });

    //查看退货详情
    function return_detail(obj) {
        // 获取当前选中行的returnId值
        var id = $(obj).parent().parent().find("td").eq(1).text();
        // 打开采购入库详情弹窗
        x_admin_show("退货详情","/returnDetail?returnId="+id,400,500);
    }

    //修改退货信息
    function return_edit(obj) {
        // 获取当前选中行的returnId值
        var id = $(obj).parent().parent().find("td").eq(1).text();
        // 打开修改弹窗
        x_admin_show("修改退货信息","/returnEdit?returnId="+id,400,500);
    }

    /*采购入库记录-删除*/
    function return_del(obj) {
        // 获取当前选中行的userId值
        var id = $(obj).parent().parent().find("td").eq(1).text();
        // layui的提示框确定用户是否删除
        layer.confirm("你确定要删除此退货记录吗？",{icon:3,title:"提示"},function(index){
            $.ajax({
                url:"/delReturn",
                type:"get",
                data:{"returnId":id},
                dataType:"json",
                success:function(data){
                    layer.alert(data.info);
                    if(data.info == "删除成功"){
                        //刷新页面
                        $(obj).parent().parent().remove();
                    }
                }
            })
        });
    }

    //批量删除
    function delAll(arguments) {
        var data = tableCheck.getData();
        var values=[]

        $("input[name='getId']:checked").each(function(){
            var value={"returnId":$(this).val()}
            values.push(value)
        });
        console.log(values);
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                url:"/delAll",
                type:"post",
                data:JSON.stringify(values),
                dataType:"json",
                contentType : 'application/json',
                success:function (data) {
                    layer.alert(data.info);
                    if(data.info=="删除成功"){
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }
                }
            })
            layer.close(index);

        });
    }
</script>

<script>
    var _hmt = _hmt || []; (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
</body>

</html>